2013 Aug 09 1:12 PM
Dear All,
I am trying to create a program through which we can generate ABAP code which will save atleast minimum of developer efforts. Could some please help me in identifying where to start with ? Currently I am importing an excel (A Template kind of stuff) and I am typing the syntax based on the template and using the below statement to create a program in R/3. INSERT REPORT program FROM codings PROGRAM TYPE '1'.
Can anyone suggest some better methodology/technology which could be used ?
With reference to the below link
http://scn.sap.com/thread/343181
Could some help me in understanding how to use the FM 'RSS_TEMPLATE_INSTANTIATE'. In the attached link, what are we supposed to pass to C_TEMPLATE in the FM ?
Thanks in advance for your time and help !!
Thanks,
Kausthub
2013 Aug 09 1:31 PM
2013 Aug 09 1:31 PM
2013 Aug 09 1:35 PM
Hi Fred,
The purpose of SGEN is different. We run it after we import a support pack / system upgrades. What I am expecting to develop is a tool which will output ABAP Code (Atleast for basic requirements so that we can reuse it and need not code same each and every time).
Thanks,
Kausthub
2013 Aug 09 2:28 PM
Hello,
Check this : http://help.sap.com/saphelp_40b/helpdata/en/92/58b476417011d189ec0000e81ddfac/content.htm
Thanks
Katrice
2013 Aug 09 2:45 PM
Hello,
This is only for API Calls. When i see the program behind this tcode, abap syntax is manually added. Is this the only way (Type in the syntax based on the input) to build a tool which will generate abap code ?
Can you also have a look in the function module which i have published?
Thank you very much !
regards,
Kausthub
2013 Aug 09 4:58 PM
Try this code.
Unfortunately it is in italian (messages and comments) but I believe is quite easy to understand.
REPORT zbc_generate MESSAGE-ID zmsgmm.
************************************************************************
*--------> Dichiarazione Dati e Parametri <------*
************************************************************************
TABLES: trdir. " Tabella di sistema TRDIR
DATA: BEGIN OF t_report OCCURS 0,
lines(200),
END OF t_report.
SELECTION-SCREEN: BEGIN OF BLOCK frame WITH FRAME.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-s04.
SELECTION-SCREEN: BEGIN OF LINE.
PARAMETERS : r_crea RADIOBUTTON GROUP flus DEFAULT 'X'
USER-COMMAND upd.
SELECTION-SCREEN: COMMENT 3(28) text-s05.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN: BEGIN OF LINE.
PARAMETERS : r_dele RADIOBUTTON GROUP flus.
SELECTION-SCREEN: COMMENT 3(28) text-s06.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN:END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s01.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 1(28) text-s02 MODIF ID fil.
PARAMETERS: p_path LIKE rlgrap-filename MODIF ID fil.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 1(28) text-s03.
PARAMETERS: p_nome(8) OBLIGATORY DEFAULT 'ZDA_CANC'.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN:END OF BLOCK b1.
SELECTION-SCREEN:END OF BLOCK frame.
************************************************************************
*--------> MAIN PROGRAMMA <------*
************************************************************************
*------------------------------*
AT SELECTION-SCREEN.
*------------------------------*
CHECK sy-ucomm = 'ONLI'.
PERFORM controlli.
IF r_crea = 'X'.
PERFORM upload.
ELSE.
PERFORM cancella.
ENDIF.
*------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*------------------------------------------------*
PERFORM get_filename.
*------------------------------*
AT SELECTION-SCREEN OUTPUT.
*------------------------------*
PERFORM init_selscreen.
************************************************************************
*--------> SVILUPPO FORM <------*
************************************************************************
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM get_filename.
DATA: t_filetable TYPE filetable,
st_file TYPE file_table,
w_rc TYPE i.
CLEAR: t_filetable, w_rc, st_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Percorso File Input'
multiselection = ' '
CHANGING
file_table = t_filetable
rc = w_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
CHECK w_rc = 1.
READ TABLE t_filetable INTO st_file INDEX 1.
CHECK sy-subrc = 0.
p_path = st_file-filename.
ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form attiva_selezioni
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM init_selscreen.
* --> Schermo 1000 (selection-screen)
IF sy-dynnr = '1000'.
LOOP AT SCREEN.
IF screen-group1 EQ 'FIL'.
IF r_crea = ' '.
screen-invisible = 1.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " init_selscreen
*&---------------------------------------------------------------------*
*& Form controlli
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM controlli.
* --> Percorso file obbligatrorio per Creazione
IF r_crea = 'X' AND p_path IS INITIAL.
SET CURSOR FIELD 'P_PATH'.
MESSAGE e005.
ENDIF.
* --> Controllo nome programma
IF p_nome NE 'ZDA_CANC'.
IF r_crea = 'X'.
SELECT SINGLE * FROM trdir WHERE name = p_nome.
IF sy-subrc = 0.
MESSAGE e000 WITH 'Programma esistente: non sovrascivere'.
ENDIF.
ELSE.
SET CURSOR FIELD 'P_NOME'.
MESSAGE e000 WITH 'Cancellare solo ZDA_CANC'.
ENDIF.
ENDIF.
ENDFORM. "controlli
*&---------------------------------------------------------------------*
*& Form upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM upload.
CLEAR t_report. REFRESH t_report.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = p_path
TABLES
data_tab = t_report
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
INSERT REPORT p_nome FROM t_report PROGRAM TYPE '1'.
ENDFORM. "upload
*&---------------------------------------------------------------------*
*& Form cancella
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM cancella.
DELETE REPORT p_nome.
IF sy-subrc = 0.
MESSAGE i000 WITH 'Azione eseguita con successo'.
ELSE.
MESSAGE i000 WITH 'Imposssibile cancellare il pgm'.
ENDIF.
ENDFORM. "cancella
*Text elements
*-------------
* IS01 Paramentri Selezione
* IS02 Percorso File
* IS03 Nome Programma
* IS04 Scelta Azione
* IS05 Crea Nuovo
* IS06 Elimina
*Messages
*-------------
* Message class: ZMSGMM
* 000 & & & &
* 005 Valorizzare il campo &
2013 Aug 09 5:29 PM
Hey Moody,
Thank your very much for your response.
If i understand correctly, this flat file has ABAP Code. The source code you mentioned just imports the file to a table and creates a program in SAP with the content inside the file (Which is ABAP Code)
What i need is, my program in SAP, should generate another ABAP program based on Interactive Module Pool @Selection screen or Excel as input (Excel will be kind of technical specification)
So the only way to do this is to read the excel and type in the ABAP Code (Generalize it), Keep in an ITAB, and then create a new program like INSERT REPORT ZTEST FROM ITAB ? (or) Is there any other way where we can generate ABAP code (Through an ABAP Code )
Thanks,
kausthub
2013 Aug 09 7:11 PM
What you want is something similar to an ALV generator, right? I've already worked in a few programs like these.
I don't know anything standard that will generated good code automatically. If you want your "program generator" to care about performance, best practices, security and such, you'll have to add the syntax manually to an internal table before creating the program.
One tip I can give, is using the automated functions to create the objects. Don't simply use "INSERT REPORT". Use functions like TR_TADIR_INTERFACE, which will handle package assignment and request generation automatically. (Eg.: If you're going to create a FUNCTION, debug the "Create" option in SE37 to find the correct FM to generate the object.)
Good luck!
2013 Aug 09 7:16 PM
Dear Cruz,
Exactly You have understood my requirement.
Thanks for your suggestions. I will keep it in my mind. I have already started developing my tool.
I will publish it once done.
Regards,
Kausthub
2013 Aug 12 9:00 AM
An example of FM generation can be seen in FM /SPE/QUEUE_CONTAINER_SHOW. It uses FM FUNCTION_CREATE to generate new FM's in its function group.
2013 Aug 09 7:57 PM
How about if you built components (FM's or OO Methods) that you could feed with assign field symbols?
Creating generated code generates code that has to made either very limiting assumptions or has to handle an absurd set of possibilities. That's why SAP Query and SAP Report Writer / Report Painter are so useless!
Neal
2013 Aug 09 8:03 PM
Hi Neal,
Thanks for your reply.
So basically you are asking me to split each part of the source code generation into various components (Using FM , OO Method) right ? If so, could you please elaborate your suggestion ? This will be very helpful. Thank you very much.
Regards,
Kausthub
2013 Aug 12 4:01 PM
Every FM / OO method can be considered a black box. It has inputs and outputs. Suppose that you know that people often want to do "X". "X" has steps 1 - 10. The condition of the Stack before the process are the inputs to "X" and the condition of the stack after the process is run is the outputs from "X". You can simplify this by saying that anything in the stack that can not be changed by "X" need not be included in Input or Output.
So, now you can build "X" as a static FM in SAP.
This simplifies your code creation needs by only requiring you to write a generator the call to X in order to have the created program perform "X".
Now obviously Fm's and OO Methods won't need to be "feed with assign field symbols". However you can also use remote performs in a static Include program. These could be "feed with assign field symbols".
Neal
2013 Aug 09 9:35 PM
You should check GENERATE SUBROUTINE POOL.
This is an excerpt from SAP's documentation :
DATA: prog TYPE string,
tab TYPE STANDARD TABLE OF string,
mess TYPE string,
sid TYPE string.
APPEND 'PROGRAM subpool.' TO tab.
APPEND `DATA spfli_tab TYPE TABLE OF spfli.` TO tab.
APPEND `LOAD-OF-PROGRAM.` TO tab.
APPEND ` SELECT *` &
` FROM spfli` &
` INTO TABLE spfli_tab.` TO tab.
APPEND `FORM loop_at_tab.` TO tab.
APPEND ` DATA spfli_wa TYPE spfli.` TO tab.
APPEND ` LOOP AT spfli_tab INTO spfli_wa.` TO tab.
APPEND ` PERFORM evaluate_wa USING spfli_wa.` TO tab.
APPEND ` ENDLOOP.` TO tab.
APPEND `ENDFORM.` TO tab.
APPEND `FORM evaluate_wa USING l_wa TYPE spfli.` TO tab.
APPEND ` WRITE: / l_wa-carrid, l_wa-connid.` TO tab.
APPEND `ENDFORM.` TO tab.
GENERATE SUBROUTINE POOL tab NAME prog
MESSAGE mess
SHORTDUMP-ID sid.
IF sy-subrc = 0.
PERFORM ('LOOP_AT_TAB') IN PROGRAM (prog) IF FOUND.
ELSEIF sy-subrc = 4.
MESSAGE mess TYPE 'I'.
ELSEIF sy-subrc = 8.
MESSAGE sid TYPE 'I'.
ENDIF.
Can be very helpful - at times.
Regards,
Chris
2013 Aug 10 4:06 AM
Hi Kausthub KrishnaKumar,
Could some help me in understanding how to use the FM 'RSS_TEMPLATE_INSTANTIATE'. In the attached link, what are we supposed to pass to C_TEMPLATE in the FM ?
See this link http://scn.sap.com/thread/467912
you will get idea on how to use RSS_TEMPLATE_INSTANTIATE.
Regards,
Ramesh.T