ABAP Select data from SAP table CMYFMOVLALTDDPST 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 CMYFMOVLALTDDPST 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 CMYFMOVLALTDDPST. 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 CMYFMOVLALTDDPST 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_CMYFMOVLALTDDPST TYPE STANDARD TABLE OF CMYFMOVLALTDDPST, WA_CMYFMOVLALTDDPST TYPE CMYFMOVLALTDDPST, 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: <CMYFMOVLALTDDPST> TYPE CMYFMOVLALTDDPST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CMYFMOVLALTDDPST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CMYFMOVLALTDDPST INTO TABLE IT_CMYFMOVLALTDDPST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CMYFMOVLALTDDPST * INTO TABLE @DATA(IT_CMYFMOVLALTDDPST2). *--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_CMYFMOVLALTDDPST INDEX 1 INTO DATA(WA_CMYFMOVLALTDDPST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CMYFMOVLALTDDPST ASSIGNING <CMYFMOVLALTDDPST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CMYFMOVLALTDDPST>-MANDT = 1.
<CMYFMOVLALTDDPST>-FINANCIALMANAGEMENTAREA = 1.
<CMYFMOVLALTDDPST>-AVAILABILITYCONTROLLEDGER = 1.
<CMYFMOVLALTDDPST>-FINMGMTAREAFISCALYEAR = 1.
<CMYFMOVLALTDDPST>-BDGTCASHEFFECTIVITYFISCALYEAR = 1.
ENDLOOP. LOOP AT IT_CMYFMOVLALTDDPST INTO WA_CMYFMOVLALTDDPST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CMYFMOVLALTDDPST-CONTROLOBJECTCOVERGROUP, sy-vline,
WA_CMYFMOVLALTDDPST-CONTROLOBJECTGRANTID, sy-vline,
WA_CMYFMOVLALTDDPST-CONTROLOBJECTFUND, sy-vline,
WA_CMYFMOVLALTDDPST-CONTROLOBJECTBUDGETPERIOD, sy-vline,
WA_CMYFMOVLALTDDPST-CONTROLOBJECTFUNDSCENTER, sy-vline,
WA_CMYFMOVLALTDDPST-CONTROLOBJECTCOMMITMENTITEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CMYFMOVLALTDDPST 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_CMYFMOVLALTDDPST 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_CMYFMOVLALTDDPST INTO WA_CMYFMOVLALTDDPST. *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_CMYFMOVLALTDDPST-AVAILABILITYCONTROLLEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-AVAILABILITYCONTROLLEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field FINMGMTAREAFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-FINMGMTAREAFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-FINMGMTAREAFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field BDGTCASHEFFECTIVITYFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-BDGTCASHEFFECTIVITYFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-BDGTCASHEFFECTIVITYFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONTROLOBJECTGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-CONTROLOBJECTGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-CONTROLOBJECTGRANTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field CONTROLOBJECTCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-CONTROLOBJECTCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-CONTROLOBJECTCOMMITMENTITEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FUNDSMGMTJOURNALENTRY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-FUNDSMGMTJOURNALENTRY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-FUNDSMGMTJOURNALENTRY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-LEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REFERENCEDOCUMENTLOGICALSYSTEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-REFERENCEDOCUMENTLOGICALSYSTEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-REFERENCEDOCUMENTLOGICALSYSTEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field POSTEDGRANTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-POSTEDGRANTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-POSTEDGRANTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field POSTEDCOMMITMENTITEM CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-POSTEDCOMMITMENTITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-POSTEDCOMMITMENTITEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CASHEFFECTIVITYFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_CMYFMOVLALTDDPST-CASHEFFECTIVITYFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CMYFMOVLALTDDPST-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_CMYFMOVLALTDDPST_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_CMYFMOVLALTDDPST_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_CMYFMOVLALTDDPST_STR-MANDT sy-vline
WA_CMYFMOVLALTDDPST_STR-FINANCIALMANAGEMENTAREA sy-vline
WA_CMYFMOVLALTDDPST_STR-AVAILABILITYCONTROLLEDGER sy-vline
WA_CMYFMOVLALTDDPST_STR-FINMGMTAREAFISCALYEAR sy-vline
WA_CMYFMOVLALTDDPST_STR-BDGTCASHEFFECTIVITYFISCALYEAR sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTCOVERGROUP sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTGRANTID sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTFUND sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTBUDGETPERIOD sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTFUNDSCENTER sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTCOMMITMENTITEM sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTFUNCTIONALAREA sy-vline
WA_CMYFMOVLALTDDPST_STR-CONTROLOBJECTFUNDEDPROGRAM sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMOVLALTDDPST_STR-FINANCIALMANAGEMENTAREACRCY sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTJOURNALENTRY sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTJOURNALENTRYITEM sy-vline
WA_CMYFMOVLALTDDPST_STR-LEDGER sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTAMOUNTTYPE sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTREFDOCUMENTCATEGORY sy-vline
WA_CMYFMOVLALTDDPST_STR-REFERENCEDOCUMENTTYPE sy-vline
WA_CMYFMOVLALTDDPST_STR-REFDOCACCOUNTASSIGNMENT sy-vline
WA_CMYFMOVLALTDDPST_STR-REFERENCEDOCUMENTSCHEDULELINE sy-vline
WA_CMYFMOVLALTDDPST_STR-REFDOCPRICINGELEMENTCONTENT sy-vline
WA_CMYFMOVLALTDDPST_STR-REFERENCEDOCUMENTLOGICALSYSTEM sy-vline
WA_CMYFMOVLALTDDPST_STR-REFERENCEDOCUMENTCONTEXT sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTLONGSEQUENCENUMBER sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJGRANTNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNDTYPE sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNDNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJBUDGETPERIODNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNDSCENTERNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJCOMMITMENTITEMCATEGORY sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJCOMMITMENTITEMNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNCTIONALAREANAME sy-vline
WA_CMYFMOVLALTDDPST_STR-CTRLOBJFUNDEDPROGRAMNAME sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDGRANTID sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDFUND sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDBUDGETPERIOD sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDFUNDSCENTER sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDCOMMITMENTITEM sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDFUNCTIONALAREA sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDFUNDEDPROGRAM sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDFUNDSMGMTCUSTOMERFIELD sy-vline
WA_CMYFMOVLALTDDPST_STR-COMPANYCODE sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGMTVALUETYPE sy-vline
WA_CMYFMOVLALTDDPST_STR-CASHEFFECTIVITYFISCALYEAR sy-vline
WA_CMYFMOVLALTDDPST_STR-BUSINESSTRANSACTIONTYPE sy-vline
WA_CMYFMOVLALTDDPST_STR-FUNDSMGCARRYFORWARDLEVEL sy-vline
WA_CMYFMOVLALTDDPST_STR-FINMGMTAREAPERIOD sy-vline
WA_CMYFMOVLALTDDPST_STR-POSTEDAMOUNTINFMACRCY sy-vline
WA_CMYFMOVLALTDDPST_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.