Batch-Input FORM

This is the way I use Batch-Inputs. I hate them, and I can tell you thousand reasons (well, maybe three) to keep them away if able. But sometimes a tie-wearer comes to me and asks me politely (or not) to use one. The main goal of this post is to keep my method available through all possible workplaces I’ll fall (if they’ll allow me to reach this site, of course).
Another goal is to have someone with real knowledge taking an eye over it and pointing me the weak points of this crappy code.

Through macroes, because I don’t like the BDC include (yes, I’m a moron)
DATA: wa_bdc TYPE bdcdata,
it_bdc LIKE TABLE OF bdcdata.
DATA: wa_params LIKE ctu_params.
DATA: wa_err TYPE bdcmsgcoll,
it_err TYPE TABLE OF bdcmsgcoll,
it_re2 TYPE TABLE OF bapiret2.
DATA: l_prec(11) TYPE c.
DATA: wa_t006 TYPE t006.
wa_params-dismode = 'N'.
wa_params-updmode = 'S'.
* Dynpro Macro
DEFINE dodynpro.
clear wa_bdc.
wa_bdc-dynbegin = &1.
wa_bdc-program = &2.
wa_bdc-dynpro = &3.
append wa_bdc to it_bdc.
* Field Macro
DEFINE dofield.
clear wa_bdc.
wa_bdc-fnam = &1.
wa_bdc-fval = &2.
append wa_bdc to it_bdc.
REFRESH it_bdc.

After it, I call the bdc through those macroes, in this example, for t-code VK11
* Initial screen
dodynpro 'X' 'SAPMV13A' '0100'.
dofield 'BDC_OKCODE' '/00'.
dofield 'RV13A-KSCHL' c_zprc.
* grid screen: header and data check (enter)
dodynpro 'X' 'SAPMV13A' '1902'.
dofield 'BDC_OKCODE' '/00'.
dofield 'KOMG-VKORG' wa_dat-vkorg.
dofield 'KOMG-VTWEG' p_canal.
dofield 'KOMG-SPART' wa_dat-spart.
* grid screen: first line and data check (enter)
dodynpro 'X' 'SAPMV13A' '1902'.
dofield 'BDC_CURSOR' 'RV13A-DATBI(01)'.
dofield 'BDC_OKCODE' '/00'.
dofield 'KOMG-ZZKUNZL(01)' c_14990.
dofield 'KOMG-ZZFERTH(01)' wa_dat-ferth.
MOVE wa_dat-precio TO l_prec.
REPLACE '.' WITH ',' INTO l_prec.
CONDENSE l_prec.
dofield 'KONP-KBETR(01)' l_prec.
dofield 'KONP-KMEIN(01)' c_1.
dofield 'KONP-KONWA(01)' c_eur.
* Meas. Unit: buscar with sy-langu
INTO wa_dat-meins
FROM t006a
WHERE spras = sy-langu
AND msehi = wa_dat-meins.
dofield 'KONP-KMEIN(01)' wa_dat-meins.
* saving
dodynpro 'X' 'SAPMV13A' '1902'.
dofield 'BDC_CURSOR' 'KOMG-BZIRK(01)'.
dofield 'BDC_OKCODE' '=SICH'.
Then, the CALL TRANSACTION and the error checking:
OPTIONS FROM wa_params
CHECK LINES( it_err ) > 0.
imt_bdcmsgcoll = it_err
ext_return = it_re2.
APPEND LINES OF it_re2 TO it_ret.

If we get our BI coding from the recorder, we can export the recorded session to a file, and then use some kind of spreadsheet with formulae to get the macro calls.
Like this one (in Ms Excel):
BI converter sample
The formula shown belongs to the Spanish version, but can be “translated” to English easy:

=SI(O(B2=0;ESBLANCO(B2));”field ‘” & D2 & “‘ ‘” & E2 & “‘.”;”dynpro ‘X’ ‘” & TEXTO(A2;”0000″) & “‘ ‘” & B2 &”‘.”)

=IF(OR(B2=0;ISNULL(B2));”field ‘” & D2 & “‘ ‘” & E2 & “‘.”;”dynpro ‘X’ ‘” & FORMAT(A2;”0000″) & “‘ ‘” & B2 &”‘.”)

Update: I had to modify the macroes to use FORMs. These are the forms:

* FORM dynpro *
FORM dynpro USING par1 par2 par3.
CLEAR wa_bdc.
wa_bdc-dynbegin = par1.
wa_bdc-program = par2.
wa_bdc-dynpro = par3.
APPEND wa_bdc TO it_bdc.

* FORM field *
FORM field USING par1 par2.
CLEAR wa_bdc.
wa_bdc-fnam = par1.
wa_bdc-fval = par2.
APPEND wa_bdc TO it_bdc.

The next step will be to change the Excel’s formula to keep the changes up to date 😉

– Formula changed to accept null values in the third column
– Attaching files for code (.txt) and spreadsheet (.xls)

ABAP code sample
The spreadsheet


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s