ABAP Select data from SAP table CMYFMANNBGTDDPST into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP CMYFMANNBGTDDPST table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to CMYFMANNBGTDDPST. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the CMYFMANNBGTDDPST table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_CMYFMANNBGTDDPST TYPE STANDARD TABLE OF CMYFMANNBGTDDPST, WA_CMYFMANNBGTDDPST TYPE CMYFMANNBGTDDPST, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <CMYFMANNBGTDDPST> TYPE CMYFMANNBGTDDPST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CMYFMANNBGTDDPST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CMYFMANNBGTDDPST INTO TABLE IT_CMYFMANNBGTDDPST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CMYFMANNBGTDDPST * INTO TABLE @DATA(IT_CMYFMANNBGTDDPST2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_CMYFMANNBGTDDPST INDEX 1 INTO DATA(WA_CMYFMANNBGTDDPST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CMYFMANNBGTDDPST ASSIGNING <CMYFMANNBGTDDPST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CMYFMANNBGTDDPST>-MANDT = 1.
<CMYFMANNBGTDDPST>-FINANCIALMANAGEMENTAREA = 1.
<CMYFMANNBGTDDPST>-AVAILABILITYCONTROLLEDGER = 1.
<CMYFMANNBGTDDPST>-FINMGMTAREAFISCALYEAR = 1.
<CMYFMANNBGTDDPST>-BDGTCASHEFFECTIVITYFISCALYEAR = 1.
ENDLOOP. LOOP AT IT_CMYFMANNBGTDDPST INTO WA_CMYFMANNBGTDDPST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CMYFMANNBGTDDPST-CONTROLOBJECTCOVERGROUP, sy-vline,
WA_CMYFMANNBGTDDPST-CONTROLOBJECTGRANTID, sy-vline,
WA_CMYFMANNBGTDDPST-CONTROLOBJECTFUND, sy-vline,
WA_CMYFMANNBGTDDPST-CONTROLOBJECTBUDGETPERIOD, sy-vline,
WA_CMYFMANNBGTDDPST-CONTROLOBJECTFUNDSCENTER, sy-vline,
WA_CMYFMANNBGTDDPST-CONTROLOBJECTCOMMITMENTITEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CMYFMANNBGTDDPST you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_CMYFMANNBGTDDPST TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_CMYFMANNBGTDDPST INTO WA_CMYFMANNBGTDDPST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ALPHA, internal->external for field AVAILABILITYCONTROLLEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-AVAILABILITYCONTROLLEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-AVAILABILITYCONTROLLEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field FINMGMTAREAFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-FINMGMTAREAFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-FINMGMTAREAFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field BDGTCASHEFFECTIVITYFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-BDGTCASHEFFECTIVITYFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-BDGTCASHEFFECTIVITYFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONTROLOBJECTGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-CONTROLOBJECTGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-CONTROLOBJECTGRANTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field CONTROLOBJECTCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-CONTROLOBJECTCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-CONTROLOBJECTCOMMITMENTITEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FUNDSMGMTJOURNALENTRY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-FUNDSMGMTJOURNALENTRY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-FUNDSMGMTJOURNALENTRY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-LEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REFERENCEDOCUMENTLOGICALSYSTEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-REFERENCEDOCUMENTLOGICALSYSTEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-REFERENCEDOCUMENTLOGICALSYSTEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field POSTEDGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-POSTEDGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-POSTEDGRANTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field POSTEDCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-POSTEDCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-POSTEDCOMMITMENTITEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CASHEFFECTIVITYFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMANNBGTDDPST-CASHEFFECTIVITYFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMANNBGTDDPST-CASHEFFECTIVITYFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_CMYFMANNBGTDDPST_STR,
MANDT TYPE STRING,
FINANCIALMANAGEMENTAREA TYPE STRING,
AVAILABILITYCONTROLLEDGER TYPE STRING,
FINMGMTAREAFISCALYEAR TYPE STRING,
BDGTCASHEFFECTIVITYFISCALYEAR TYPE STRING,
CONTROLOBJECTCOVERGROUP TYPE STRING,
CONTROLOBJECTGRANTID TYPE STRING,
CONTROLOBJECTFUND TYPE STRING,
CONTROLOBJECTBUDGETPERIOD TYPE STRING,
CONTROLOBJECTFUNDSCENTER TYPE STRING,
CONTROLOBJECTCOMMITMENTITEM TYPE STRING,
CONTROLOBJECTFUNCTIONALAREA TYPE STRING,
CONTROLOBJECTFUNDEDPROGRAM TYPE STRING,
CTRLOBJFUNDSMGMTCUSTOMERFIELD TYPE STRING,
FINANCIALMANAGEMENTAREACRCY TYPE STRING,
FUNDSMGMTJOURNALENTRY TYPE STRING,
FUNDSMGMTJOURNALENTRYITEM TYPE STRING,
LEDGER TYPE STRING,
FUNDSMGMTAMOUNTTYPE TYPE STRING,
FUNDSMGMTREFDOCUMENTCATEGORY TYPE STRING,
REFERENCEDOCUMENTTYPE TYPE STRING,
REFDOCACCOUNTASSIGNMENT TYPE STRING,
REFERENCEDOCUMENTSCHEDULELINE TYPE STRING,
REFDOCPRICINGELEMENTCONTENT TYPE STRING,
REFERENCEDOCUMENTLOGICALSYSTEM TYPE STRING,
REFERENCEDOCUMENTCONTEXT TYPE STRING,
FUNDSMGMTLONGSEQUENCENUMBER TYPE STRING,
CTRLOBJGRANTNAME TYPE STRING,
CTRLOBJFUNDTYPE TYPE STRING,
CTRLOBJFUNDNAME TYPE STRING,
CTRLOBJBUDGETPERIODNAME TYPE STRING,
CTRLOBJFUNDSCENTERNAME TYPE STRING,
CTRLOBJCOMMITMENTITEMCATEGORY TYPE STRING,
CTRLOBJCOMMITMENTITEMNAME TYPE STRING,
CTRLOBJFUNCTIONALAREANAME TYPE STRING,
CTRLOBJFUNDEDPROGRAMNAME TYPE STRING,
POSTEDGRANTID TYPE STRING,
POSTEDFUND TYPE STRING,
POSTEDBUDGETPERIOD TYPE STRING,
POSTEDFUNDSCENTER TYPE STRING,
POSTEDCOMMITMENTITEM TYPE STRING,
POSTEDFUNCTIONALAREA TYPE STRING,
POSTEDFUNDEDPROGRAM TYPE STRING,
POSTEDFUNDSMGMTCUSTOMERFIELD TYPE STRING,
COMPANYCODE TYPE STRING,
FUNDSMGMTVALUETYPE TYPE STRING,
CASHEFFECTIVITYFISCALYEAR TYPE STRING,
BUSINESSTRANSACTIONTYPE TYPE STRING,
FUNDSMGCARRYFORWARDLEVEL TYPE STRING,
FINMGMTAREAPERIOD TYPE STRING,
POSTEDAMOUNTINFMACRCY TYPE STRING,
NUMBEROFDOCUMENTITEMS TYPE STRING,END OF T_EKKO_STR. DATA: WA_CMYFMANNBGTDDPST_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_CMYFMANNBGTDDPST_STR-MANDT sy-vline
WA_CMYFMANNBGTDDPST_STR-FINANCIALMANAGEMENTAREA sy-vline
WA_CMYFMANNBGTDDPST_STR-AVAILABILITYCONTROLLEDGER sy-vline
WA_CMYFMANNBGTDDPST_STR-FINMGMTAREAFISCALYEAR sy-vline
WA_CMYFMANNBGTDDPST_STR-BDGTCASHEFFECTIVITYFISCALYEAR sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTCOVERGROUP sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTGRANTID sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTFUND sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTBUDGETPERIOD sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTFUNDSCENTER sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTCOMMITMENTITEM sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTFUNCTIONALAREA sy-vline
WA_CMYFMANNBGTDDPST_STR-CONTROLOBJECTFUNDEDPROGRAM sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMANNBGTDDPST_STR-FINANCIALMANAGEMENTAREACRCY sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTJOURNALENTRY sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTJOURNALENTRYITEM sy-vline
WA_CMYFMANNBGTDDPST_STR-LEDGER sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTAMOUNTTYPE sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTREFDOCUMENTCATEGORY sy-vline
WA_CMYFMANNBGTDDPST_STR-REFERENCEDOCUMENTTYPE sy-vline
WA_CMYFMANNBGTDDPST_STR-REFDOCACCOUNTASSIGNMENT sy-vline
WA_CMYFMANNBGTDDPST_STR-REFERENCEDOCUMENTSCHEDULELINE sy-vline
WA_CMYFMANNBGTDDPST_STR-REFDOCPRICINGELEMENTCONTENT sy-vline
WA_CMYFMANNBGTDDPST_STR-REFERENCEDOCUMENTLOGICALSYSTEM sy-vline
WA_CMYFMANNBGTDDPST_STR-REFERENCEDOCUMENTCONTEXT sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTLONGSEQUENCENUMBER sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJGRANTNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNDTYPE sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNDNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJBUDGETPERIODNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNDSCENTERNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJCOMMITMENTITEMCATEGORY sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJCOMMITMENTITEMNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNCTIONALAREANAME sy-vline
WA_CMYFMANNBGTDDPST_STR-CTRLOBJFUNDEDPROGRAMNAME sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDGRANTID sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDFUND sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDBUDGETPERIOD sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDFUNDSCENTER sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDCOMMITMENTITEM sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDFUNCTIONALAREA sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDFUNDEDPROGRAM sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMANNBGTDDPST_STR-COMPANYCODE sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGMTVALUETYPE sy-vline
WA_CMYFMANNBGTDDPST_STR-CASHEFFECTIVITYFISCALYEAR sy-vline
WA_CMYFMANNBGTDDPST_STR-BUSINESSTRANSACTIONTYPE sy-vline
WA_CMYFMANNBGTDDPST_STR-FUNDSMGCARRYFORWARDLEVEL sy-vline
WA_CMYFMANNBGTDDPST_STR-FINMGMTAREAPERIOD sy-vline
WA_CMYFMANNBGTDDPST_STR-POSTEDAMOUNTINFMACRCY sy-vline
WA_CMYFMANNBGTDDPST_STR-NUMBEROFDOCUMENTITEMS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.