ABAP Select data from SAP table CMYFMOVLBGTDDBGT 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 CMYFMOVLBGTDDBGT 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 CMYFMOVLBGTDDBGT. 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 CMYFMOVLBGTDDBGT 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_CMYFMOVLBGTDDBGT TYPE STANDARD TABLE OF CMYFMOVLBGTDDBGT,
      WA_CMYFMOVLBGTDDBGT TYPE CMYFMOVLBGTDDBGT,
      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: <CMYFMOVLBGTDDBGT> TYPE CMYFMOVLBGTDDBGT.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_CMYFMOVLBGTDDBGT.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM CMYFMOVLBGTDDBGT
  INTO TABLE IT_CMYFMOVLBGTDDBGT.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CMYFMOVLBGTDDBGT
*  INTO TABLE @DATA(IT_CMYFMOVLBGTDDBGT2).
*--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_CMYFMOVLBGTDDBGT INDEX 1 INTO DATA(WA_CMYFMOVLBGTDDBGT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CMYFMOVLBGTDDBGT ASSIGNING <CMYFMOVLBGTDDBGT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CMYFMOVLBGTDDBGT>-MANDT = 1.
<CMYFMOVLBGTDDBGT>-FINANCIALMANAGEMENTAREA = 1.
<CMYFMOVLBGTDDBGT>-AVAILABILITYCONTROLLEDGER = 1.
<CMYFMOVLBGTDDBGT>-FINMGMTAREAFISCALYEAR = 1.
<CMYFMOVLBGTDDBGT>-BDGTCASHEFFECTIVITYFISCALYEAR = 1.
ENDLOOP.

LOOP AT IT_CMYFMOVLBGTDDBGT INTO WA_CMYFMOVLBGTDDBGT.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTCOVERGROUP, sy-vline,
WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTGRANTID, sy-vline,
WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTFUND, sy-vline,
WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTBUDGETPERIOD, sy-vline,
WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTFUNDSCENTER, sy-vline,
WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTCOMMITMENTITEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CMYFMOVLBGTDDBGT 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_CMYFMOVLBGTDDBGT 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_CMYFMOVLBGTDDBGT INTO WA_CMYFMOVLBGTDDBGT. *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_CMYFMOVLBGTDDBGT-AVAILABILITYCONTROLLEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-AVAILABILITYCONTROLLEDGER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field FINMGMTAREAFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-FINMGMTAREAFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-FINMGMTAREAFISCALYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field BDGTCASHEFFECTIVITYFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BDGTCASHEFFECTIVITYFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BDGTCASHEFFECTIVITYFISCALYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CONTROLOBJECTGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTGRANTID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit FMCIL, internal->external for field CONTROLOBJECTCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-CONTROLOBJECTCOMMITMENTITEM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field BUDGETDOCUMENTYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETDOCUMENTYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETDOCUMENTYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BUDGETENTRYDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETENTRYDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETENTRYDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BUDGETVERSION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETVERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETVERSION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BUDGETCATEGORY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETCATEGORY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETCATEGORY.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BUDGETEDGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETEDGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETEDGRANTID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit FMCIL, internal->external for field BUDGETEDCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMOVLBGTDDBGT-BUDGETEDCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLBGTDDBGT-BUDGETEDCOMMITMENTITEM.
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_CMYFMOVLBGTDDBGT_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,
BUDGETDOCUMENTYEAR TYPE STRING,
BUDGETENTRYDOCUMENT TYPE STRING,
BUDGETENTRYDOCUMENTITEM 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,
BUDGETVERSION TYPE STRING,
BUDGETINGPROCESS TYPE STRING,
BUDGETENTRYDOCUMENTTYPE TYPE STRING,
BUDGETENTRYDOCUMENTSTATUS TYPE STRING,
ORIGINALBUDGETINGAPPLICATION TYPE STRING,
INTERNALBUDGETINGPROCESS TYPE STRING,
BUDGETVALUETYPE TYPE STRING,
BUDGETCATEGORY TYPE STRING,
BUDGETTYPE TYPE STRING,
BUDGETEDGRANTID TYPE STRING,
BUDGETEDFUND TYPE STRING,
BUDGETEDBUDGETPERIOD TYPE STRING,
BUDGETEDFUNDSCENTER TYPE STRING,
BUDGETEDCOMMITMENTITEM TYPE STRING,
BUDGETEDFUNCTIONALAREA TYPE STRING,
BUDGETEDFUNDEDPROGRAM TYPE STRING,
BUDGETEDFUNDSMGMTCUSTOMERFIELD TYPE STRING,
BUDGETAMOUNTINFMACRCY TYPE STRING,
NUMBEROFDOCUMENTITEMS TYPE STRING,END OF T_EKKO_STR. DATA: WA_CMYFMOVLBGTDDBGT_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_CMYFMOVLBGTDDBGT_STR-MANDT sy-vline
WA_CMYFMOVLBGTDDBGT_STR-FINANCIALMANAGEMENTAREA sy-vline
WA_CMYFMOVLBGTDDBGT_STR-AVAILABILITYCONTROLLEDGER sy-vline
WA_CMYFMOVLBGTDDBGT_STR-FINMGMTAREAFISCALYEAR sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BDGTCASHEFFECTIVITYFISCALYEAR sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTCOVERGROUP sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTGRANTID sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTFUND sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTBUDGETPERIOD sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTFUNDSCENTER sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTCOMMITMENTITEM sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTFUNCTIONALAREA sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CONTROLOBJECTFUNDEDPROGRAM sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMOVLBGTDDBGT_STR-FINANCIALMANAGEMENTAREACRCY sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETDOCUMENTYEAR sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETENTRYDOCUMENT sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETENTRYDOCUMENTITEM sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJGRANTNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNDTYPE sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNDNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJBUDGETPERIODNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNDSCENTERNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJCOMMITMENTITEMCATEGORY sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJCOMMITMENTITEMNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNCTIONALAREANAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-CTRLOBJFUNDEDPROGRAMNAME sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETVERSION sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETINGPROCESS sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETENTRYDOCUMENTTYPE sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETENTRYDOCUMENTSTATUS sy-vline
WA_CMYFMOVLBGTDDBGT_STR-ORIGINALBUDGETINGAPPLICATION sy-vline
WA_CMYFMOVLBGTDDBGT_STR-INTERNALBUDGETINGPROCESS sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETVALUETYPE sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETCATEGORY sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETTYPE sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDGRANTID sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDFUND sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDBUDGETPERIOD sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDFUNDSCENTER sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDCOMMITMENTITEM sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDFUNCTIONALAREA sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDFUNDEDPROGRAM sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETEDFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMOVLBGTDDBGT_STR-BUDGETAMOUNTINFMACRCY sy-vline
WA_CMYFMOVLBGTDDBGT_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.