how to call bapi in se37 and give output of bapi to another bapi - uri

I have 3 bapi named BAPI_SALESORDER_GETLIST,BAPI_SALESORDER_GETSTATUS and BAPI_SALESORDER_GETDETAILBOS.
Here in the first bapi I have to input Customer Number and Sales Organization as input and retrieve Sales Document Number (SD_DOC) and from_Date.
This Sales Document Number(SD_Doc) retrieved from 1st BAPI has to be given as input to other bapi named BAPI_SALESORDER_GETSTATUS to retrieve some data.
and the same Sales Document Number has to be given input to the third BAPI that is BAPI_SALESORDER_GETDETAILBOS to retrieve some particular data.
To my knowledge I have done some work with the bapi and up till now in the service I have created I have given only customer number as input to the URI in the SAP GATEWAY CLIENT
for example:
/sap/opu/odata/sap/ZOPENSALESORDER_SRV/openSalesOrderSet?$filter=Customerno eq '1'
If anyone can help regarding this would be very grateful for that.

First of all i would like to tell you guys that I have THREE bapis out of which i rquired my data.1)BAPI_SALESORDER_GETLIST 2)BAPI_SALESORDER_GETSTATUS and 3)BAPI_SALESORDER_GETDETAILBOS.
For the First Bapi i'll give input Customer Number(KUNNR) and Sales Organization(VKORG) , then i'll get sale document number as output.
This sales document number will be given to the next bapi BAPI_SALESORDER_GETSTATUS to obtain other relevant data.
And the same sales document number will also be given to the third bapi BAPI_SALESORDER_GETDETAILBOS.
I'll first tell you the steps
Specify the input parameters in the Import parameter. In my scenario i have kunnr and vkorg. click here for the image1
Then internal tables are already made as i'm only going to use the standard bapi's. so in table section just write the name of you bapi and you are good to go.click here for the image2
Then in the source section start your coding:
enter code here
DATA: "lt_bapiorders TYPE TABLE OF bapiorders,
lt_statusinfo TYPE TABLE OF bapisdstat,
lt_orderitem TYPE TABLE OF bapisditbos,
lt_orderscheduleline TYPE TABLE OF bapisdhedu.
FIELD-SYMBOLS: <lfs_order> TYPE bapiorders,
<lfs_statinfo> TYPE bapisdstat,
<lfs_orderitem> TYPE bapisditbos,
<lfs_orderscheduleline> TYPE bapisdhedu.
"Fecth all the sales order for a customer
CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
EXPORTING
customer_number = kunnr
sales_organization = vkorg
TABLES
sales_orders = order.
"Get status for the sales order
LOOP AT order ASSIGNING <lfs_order> .
IF <lfs_order> IS ASSIGNED.
WRITE:/ <lfs_order>-sd_doc.
"This function call is for getting the status of the
"Sales document number derived from the BAPI_SALESORDER_GETLIST
CALL FUNCTION 'BAPI_SALESORDER_GETSTATUS'
EXPORTING
salesdocument = <lfs_order>-sd_doc
TABLES
statusinfo = lt_statusinfo.
APPEND LINES OF lt_statusinfo TO statusinfo_lt.
"Read Processing and delivery Status
READ TABLE lt_statusinfo ASSIGNING <lfs_statinfo> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Delivery Status', <lfs_statinfo>-dlv_stat_h,
'Required Date', <lfs_statinfo>-req_date_h,
'Delivery Number',<lfs_statinfo>-deliv_numb,
'Delivery Date',<lfs_statinfo>-deliv_date.
ENDIF.
CALL FUNCTION 'BAPI_SALESORDER_GETDETAILBOS'
EXPORTING
salesdocument = <lfs_order>-sd_doc
TABLES
orderitems = lt_orderitem
orderschedulelines = lt_orderscheduleline.
APPEND LINES OF lt_orderitem to orderitem.
"Read Processing and delivery Details
READ TABLE lt_orderitem ASSIGNING <lfs_orderitem> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Material', <lfs_orderitem>-material,
'Plant', <lfs_orderitem>-plant,
'Short-text',<lfs_orderitem>-short_text,
'Req_qty',<lfs_orderitem>-req_qty,
'doc_number',<lfs_orderitem>-doc_number.
ENDIF.
APPEND LINES OF lt_orderscheduleline to orderscheduleline.
"Read processing and delivery details -goods issue time
READ TABLE orderscheduleline ASSIGNING <lfs_orderscheduleline> INDEX 1.
IF sy-subrc EQ 0.
WRITE: / 'Goods Issue Date', <lfs_orderscheduleline>-gi_date.
ENDIF.
.
ENDIF.
ENDLOOP.
Then execute it.

Related

SQLite3 creating a view profit combining rows twice based on column

Given a table
symbol|action|quantity|price
foo|buy|1|-10.00
foo|sell|1|10.50
bar|buy|1|-50.00
bar|sell|1|50.50
I am trying to create a view that shows profit per symbol
I've tried several variations of below with multiple 'order by' but not getting the expected output
create view if not exists profit_view as select symbol,sum(price * quanity) as profit from trans group by symbol;
What I'd like is a view that shows or something close to that
symbol|profit|percent
foo|.50|5
Assuming each symbol only has a single buy and sell record we can try:
SELECT
symbol,
SUM(quantity*price) AS profit,
100.0 * SUM(quantity*price) /
ABS(MAX(CASE WHEN action = 'buy' THEN quantity*price END)) AS percent
FROM trans
GROUP BY
symbol;

How to use the list the member detail AND order date by user input using WHERE condition?

I want to show the member detail by input member id then input order date greater than current date SO
I can list the all member detail but after AND condition,
it give me following error: 00933. 00000 - "SQL command not properly ended"
SELECT G_MEMBER.MEMBER_ADDRESS,
G_ORDER.PAYMENT_TYPE,G_ORDER.ORDER_DATE,G_ALBUM.ALBUM_NAME
FROM G_MEMBER
INNER JOIN G_ORDER
ON G_MEMBER.MEMBER_ID = G_ORDER.MEMBER_ID
INNER JOIN G_ALBUM
ON G_MEMBER.MEMBER_ID = G_MEMBER.MEMBER_ID
WHERE G_MEMBER.MEMBER_ID= '&MEMBER_ID'
AND G_ORDER.ORDER_DATE='&ENTER_DATE' > CURRENT_DATE; code here

MS Acess: max(Date/Time field) on query when field may contain 00:00:00

I am trying to build a Query in MS Access that returns the last date/time for a given entity ID. Research shows that using the MAX() function on the corresponding field and using GROUP BY on the remaining fields appears to be the way to go.
However, this doesn't seem to work in the presence of values that hold 0 hours, 0 minutes and 0 seconds, as it shows those values as well. The query's SQL is as follows:
SELECT Int(Historico_Classificacoes.ID_Entidade) AS ID_Entidade, Max(Historico_Classificacoes.Timestamp_Classificacao) AS [Data da última classificação], Historico_Classificacoes.US_Indicia_Pais_Constituicao, Historico_Classificacoes.US_Indicia_Responsabilidades_Fiscais, Historico_Classificacoes.US_Indicia_Morada_Coletiva, Historico_Classificacoes.US_Indicia_Telefone, Historico_Classificacoes.US_Indicia_Proveniencia_Capital, Historico_Classificacoes.US_Indicia_Beneficiários, Historico_Classificacoes.US_Indicia_Naturalidade, Historico_Classificacoes.US_Indicia_Nacionalidade, Historico_Classificacoes.US_Indicia_Morada_Singular, Historico_Classificacoes.US_Indicia_Laboral
FROM Historico_Classificacoes
GROUP BY Int(Historico_Classificacoes.ID_Entidade), Historico_Classificacoes.US_Indicia_Pais_Constituicao, Historico_Classificacoes.US_Indicia_Responsabilidades_Fiscais, Historico_Classificacoes.US_Indicia_Morada_Coletiva, Historico_Classificacoes.US_Indicia_Telefone, Historico_Classificacoes.US_Indicia_Proveniencia_Capital, Historico_Classificacoes.US_Indicia_Beneficiários, Historico_Classificacoes.US_Indicia_Naturalidade, Historico_Classificacoes.US_Indicia_Nacionalidade, Historico_Classificacoes.US_Indicia_Morada_Singular, Historico_Classificacoes.US_Indicia_Laboral
ORDER BY Int(Historico_Classificacoes.ID_Entidade);
The Historico_Classificacoes table currently holds the following data:
"ID_Entidade";"Timestamp_Classificacao";"Classificacao_DMIF";"Notacao_Risco_BCFT";"US_Indicia_Pais_Constituicao";"US_Indicia_Responsabilidades_Fiscais";"US_Indicia_Morada_Coletiva";"US_Indicia_Telefone";"US_Indicia_Proveniencia_Capital";"US_Indicia_Beneficiários";"US_Indicia_Naturalidade";"US_Indicia_Nacionalidade";"US_Indicia_Morada_Singular";"US_Indicia_Laboral"
"62";20/9/2015 00:00:00;1;30;1;1;1;1;1;1;1;1;1;0
"62";28/9/2015 10:43:38;1;30;1;1;1;1;1;1;1;1;1;1
"62";29/9/2015 17:52:24;1;30;1;1;1;1;1;1;1;1;1;1
"62";29/9/2015 17:52:40;1;30;1;1;1;1;1;1;1;1;1;1
"98";20/9/2015 00:00:00;2;15;1;1;1;1;1;1;0;0;0;0
"98";20/9/2015 00:00:01;0;0;0;0;0;0;0;0;0;0;0;0
The query, when executed in Datasheet View, outputs the following:
"ID_Entidade";"Data da última classificação";"US_Indicia_Pais_Constituicao";"US_Indicia_Responsabilidades_Fiscais";"US_Indicia_Morada_Coletiva";"US_Indicia_Telefone";"US_Indicia_Proveniencia_Capital";"US_Indicia_Beneficiários";"US_Indicia_Naturalidade";"US_Indicia_Nacionalidade";"US_Indicia_Morada_Singular";"US_Indicia_Laboral"
62;29/9/2015 17:52:40;1;1;1;1;1;1;1;1;1;1
62;20/9/2015 00:00:00;1;1;1;1;1;1;1;1;1;0
98;20/9/2015 00:00:00;1;1;1;1;1;1;0;0;0;0
98;20/9/2015 00:00:01;0;0;0;0;0;0;0;0;0;0
There are duplicated records for entities 62 and 98, when only one record for each was expected. Am I missing something here? Why are the entries whose values hold 00:00:00 present?
You may want to consider using an additional query as an intermediate step that identifies the MAX Date/Time combination for each group ID first, then a follow up query that pulls the entire record where that Group ID, Date and Time match, this will ensure you won't have to use First or Min on the rest of your fields, and you will always get the correct data
You use Group By for the last fields like US_Indicia_Morada_Singular and US_Indicia_Laboral. You'll have to use First, Last, Min, or Max on these as well.
Here is your attempt (without the repeated alias)
SELECT INT(ID_Entidade) AS ID_Entidade
, MAX(Timestamp_Classificacao) AS [Data da última classificação]
, US_Indicia_Pais_Constituicao
, US_Indicia_Responsabilidades_Fiscais
, US_Indicia_Morada_Coletiva
, US_Indicia_Telefone
, US_Indicia_Proveniencia_Capital
, US_Indicia_Beneficiários
, US_Indicia_Naturalidade
, US_Indicia_Nacionalidade
, US_Indicia_Morada_Singular
, US_Indicia_Laboral
FROM Historico_Classificacoes
GROUP BY INT(ID_Entidade)
, US_Indicia_Pais_Constituicao
, US_Indicia_Responsabilidades_Fiscais
, US_Indicia_Morada_Coletiva
, US_Indicia_Telefone
, US_Indicia_Proveniencia_Capital
, US_Indicia_Beneficiários
, US_Indicia_Naturalidade
, US_Indicia_Nacionalidade
, US_Indicia_Morada_Singular
, US_Indicia_Laboral
ORDER BY INT(ID_Entidade);
From you comments, here is SQL that is close to what you need. I have added the field "AnotherField" for you as you may or may not need to add field here.
This currently selects the whole record from the table, but only the single "most recent" record for each value found in the AnotherField is listed.
It may be that you need more that one field where AnotherField appears in the SQL. Think of the field you use instead of AnotherField as being the fields that need to be used to find the maximum date record.
SELECT Main.*
FROM Historico_Classificacoes AS Main
INNER JOIN ( SELECT AnotherField
, MAX(Timestamp_Classificacao) AS [MaxDate]
FROM Historico_Classificacoes
GROUP BY AnotherField
)
AS MostRecent
ON ( Main.AnotherField = MostRecent.AnotherField
AND
Main.Timestamp_Classificacao = MostRecent.MaxDate
)

MS Access IIF Field Exists

I am creating a report from a query where a field ABC is displayed as CAT if yes and as MOUSE if no. But unfortunately, when there are instances where the table inside the query does not contain field ABC, the report generates a error pop-up. Is there any way to by-pass this and run the report with other fields excluding the missing field?
I heard that IIF Exist function could help, but I am really blank here. I wrote the access query like below:
Iif (fieldExists(iif([ABC]=5, 'CAT', 'MOUSE'),iif([ABC]=5, 'CAT', 'MOUSE'), '')) AS TOMnJERRY
This function is maybe the shortest one to test if a field exists in Access:
Function FieldExists(ByVal Table As String, ByVal Field As String) As Boolean
On Error Resume Next
FieldExists = (DCount(Field, Table) >= 0)
End Function
How it works:
If the field exists, the expression (DCount(Field, Table) >= 0) is obviously always true, because DCount never returns a negative value. If the field doesn't exist, an error will occur and the program will jump to the next line without setting the return variable FieldExist, so this one will keep at default and this is false.
So the solution for your problem should look like this:
Iif (FieldExists('YourTable','ABC'), iif([ABC]=5, 'CAT', 'MOUSE'), '')

SQLITE getting trigger to check against table1 and insert into table2

I have a reservation table which the user will insert records into.
The User does not select the car just the type.
Once the record is inserted I want some triggers to do the following:-
The date and vehicle combination to a log file the data and vehicle are UNIQUE(date,car) so the same reservation cannot be made twice therefore a car cannot be double booked.
SO my issue is how do I now get the trigger to select the next available car of that type?
I can get it to select the next car by just saying Car.carid != Log.carid but that is not using the date as a second check so I could not then use the vehicle on another date.
Simply putting AND between the check doesnt work meaning
WHERE Car.carid != Log.carid AND Reservation.date != C.datewhen
Some guidance would be much appreciated!
I think this query is what you are after...
SELECT MIN(c.carid)
FROM all_cars c
WHERE c.type = 'CAR TYPE'
AND NOT EXISTS
(SELECT 1
FROM reservation r
WHERE r.date = 'THE DATE'
AND r.carid = c.carid)
If the query returns a NULL value then no cars are available.
Or you could take off the MIN and just use the first record returned.

Resources